import random
import string
data = {'52083147': ['张三', '123456', '北京', 500, '建设银行'],
        '52083148': ['李四', '123456', '北京', 500, '建设银行']}


def add():
    if len(data) == 100:
        return 3
    result = ''.join(random.sample(string.digits,8))
    if result in data:
        return 2
    data.setdefault(result,[])
    name = input('请输入姓名:')
    data.setdefault(result,[]).append(name)
    password = input('请设置密码:')
    data.setdefault(result, []).append(password)
    address = input('请输入地址:')
    data.setdefault(result, []).append(address)
    data.setdefault(result, []).append(0)
    bankname = input('请输入开户行名:')
    data.setdefault(result, []).append(bankname)
    print('用户添加成功,该用户的账号为:',result)
    return 1


def deposit():
    account = input('请输入您的账号:')
    if account not in data:
        return False
    num = int(input('请输入您存入的金额:'))
    data[account][3] = data[account][3] + num
    return True

def outmoney():
    account = input('请输入您的账号:')
    if account not in data:
        return 1
    password = input('请输入您的密码:')
    if data[account][1] != password:
        return 2
    num = input('请输入您取出的金额:')
    if data[account][3] < num:
        return 3
    data[account][3] = data[account][3] - num
    return 0

def transfer():
    account1 = input('请输入您要转出的账号:')
    if account1 not in data:
        return 1
    account2 = input('请输入您要转入的账号:')
    if account2 not in data:
        return 1
    password = input('请输入您要转出账号的密码:')
    if data[account1][1] != password:
        return 2
    num = int(input('请输入您转出的金额:'))
    if data[account1][3] < num:
        return 3
    data[account1][3] = data[account1][3] - num
    data[account2][3] = data[account2][3] + num
    return 0

def sel():
    account = input('请输入您的账号:')
    if account not in data:
        print('该用户不存在')
        return 1
    password = input('请输入您的密码:')
    if data[account][1] != password:
        print('密码错误')
        return 2
    print('当前账号:',account)
    print('用户名:', data[account][0])
    print('密码:',password)
    print('用户居住地址:',data[account][2])
    print('余额:',data[account][3])
    print('当前账户的开户行:',data[account][4])


def menuM():
    # while True:
    print('*' * 40)
    print("*              中国工商银行              *")
    print("*              账户管理系统              *")
    print('*' * 40)
    print("*1.开户                                 *")
    print("*2.存钱                                 *")
    print("*3.取钱                                 *")
    print("*4.转账                                 *")
    print("*5.查询                                 *")
    print("*6.Bye                                 *")
    k = int(input('请输入你要进行的操作：'))
    if k < 1 or k > 6:
        print('输入错误，请重新输入')
        k = 0
    return k

def login():
    k = menuM()
    c = -1
    if k == 0:
        login()
    elif k == 1:
        c = add()
        if c == 1:
            pass
        elif c == 2:
            print('用户已存在')
        elif c == 3:
            print('用户库已满')
        login()
    elif k == 2:
        d = deposit()
        if d == False:
            print('账号不存在')
        if d == True:
            print('存钱成功')
        login()
    elif k == 3:
        c = outmoney()
        if c == 0:
            print('取钱成功')
        elif c == 1:
            print('账号不存在')
        login()
    elif k == 4:
        c = transfer()
        if c == 0:
            print('转账成功')
        elif c == 1:
            print('账号错误')
        elif c == 2:
            print('密码错误')
        elif c == 3:
            print('余额不足')
        login()
    elif k == 5:
        sel()
        login()
    elif k == 6:
        return 0

login()